package com.zzw.basic.java;

public class FinalizerTest {

	public static FinalizerTest object;
	
	private void isAlive() {
		System.out.println("i'm alive");
	}
	
	@Override
	protected void finalize() throws Throwable {
		super.finalize();
		System.out.println("method finalize is running");
		object = this;
	}

	
	public static void main(String[] args) {
		object = new FinalizerTest();
		
		object = null;
		System.gc();
		
		try {
			Thread.sleep(500);
			if(object != null){
				object.isAlive();
			}
			else{
				System.out.println("i'm dead");
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		
		object = null;
		System.gc();
		
		try {
			Thread.sleep(500);
			if(object != null){
				object.isAlive();
			}
			else{
				System.out.println("i'm dead");
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}